<template>
  <div>
    <h1>参与拼团列表</h1>
  </div>

  <el-form :model="searchForm" :inline="true" style="width: 300px">
    <el-form-item label="拼团状态" style="width: 250px">
      <el-select v-model="searchForm.typeId" placeholder="请选择" clearable>
        <el-option label="已开团" :value="0" />
        <el-option label="未开团" :value="1" />
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="LoadList()">搜索</el-button>
    </el-form-item>
  </el-form>

  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="groupId" label="拼团id" width="180" />
      <el-table-column prop="joinId" label="活动id" width="180" />
      <el-table-column prop="teamHeader" label="团长" />
      <el-table-column prop="teamLimit" label="参团人数" />
      <el-table-column prop="joinNum" label="成团人数" />
      <el-table-column prop="beginTime" label="开始时间" />
      <el-table-column prop="endTime" label="结束时间" />
      <el-table-column prop="groupStatus" label="拼团状态">
        <template #default="scope">
          <el-button type="primary" v-if="scope.row.groupStatus == 0"
            >已开团</el-button
          >
          <el-button type="primary" v-if="scope.row.groupStatus == 1"
            >未开团</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
  <div class="demo-pagination-block">
    <el-pagination
      v-model:current-page="searchForm.pageNum"
      v-model:page-size="searchForm.pageSize"
      :page-sizes="[1, 2, 3, 4]"
      :disabled="disabled"
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
const tableData = ref([]);
import { groupList, saveGroupFun } from "@/api/api";
import { ElMessage } from "element-plus";
const searchForm = ref({
  keyWord: "",
  pageNum: 1,
  pageSize: 2,
  typeId: null,
});
const total = ref(0);
const background = ref(false);
const disabled = ref(false);

const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  searchForm.value.pageSize = val;
  LoadList();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  searchForm.value.pageNum = val;
  LoadList();
};

const LoadList = () => {
  groupList(searchForm.value).then((res) => {
    if (res.data.code == 200) {
      ElMessage.success("展示成功");
      tableData.value = res.data.data.records;
      total.value = res.data.data.total;
    }
  });
};

onMounted(() => {
  LoadList();
});
</script>

<style scoped></style>
